package com;

import com.pojo.Employee;
import com.utils.MyBatisUtils;
import org.apache.ibatis.session.SqlSession;
import org.junit.Test;

public class EmployeeTest {
    @Test
    public void findEmployeeByIdTest() {
        SqlSession sqlSession = MyBatisUtils.getSqlSession();
        Employee employee = sqlSession.selectOne("selectByPrimaryKey", 3);
        System.out.println(employee.toString());
        sqlSession.commit();
        sqlSession.close();
    }
    @Test
    public void addEmployeeTest() {
        SqlSession sqlSession = MyBatisUtils.getSqlSession();
        Employee employee = new Employee();
        employee.setId(4);
        employee.setName("赵六");
        employee.setAge(16);
        employee.setPosition("临时工");
        int addInt = sqlSession.insert("insert", employee);
        sqlSession.commit();
        sqlSession.close();
        System.out.println(addInt);
    }
    @Test
    public void updateEmployeeTest() {
        SqlSession sqlSession = MyBatisUtils.getSqlSession();
        Employee employee = new Employee();
        employee.setId(2);
        employee.setName("赵六");
        employee.setAge(16);
        employee.setPosition("临时工");
        int u = sqlSession.update("updateByPrimaryKeySelective", employee);
        sqlSession.commit();
        sqlSession.close();
        System.out.println(u);
    }
    @Test
    public void deleteEmployeeById() {
        SqlSession sqlSession = MyBatisUtils.getSqlSession();
        int d = sqlSession.delete("deleteByPrimaryKey", 1);
        sqlSession.commit();
        sqlSession.close();
        System.out.println(d);
    }
}
